package com.yl.chainStore.entity.warehouse

import com.baomidou.mybatisplus.annotation.IdType
import com.baomidou.mybatisplus.annotation.TableField
import com.baomidou.mybatisplus.annotation.TableId
import com.baomidou.mybatisplus.annotation.TableName
import com.yl.users.common.NeedGerId
import com.yl.chainStore.common.enums.Status
import com.yl.chainStore.util.GenerateNum
import com.yl.common.annotation.NoArg
import com.yl.common.getContext
import java.util.*

/**
 * <p>
 * 仓库物品调动单
 * </p>
 *
 * @author cxw
 * @since 2021-06-10
 */
@NoArg
@TableName("warehouse_dispatch_order")
class WarehouseDispatchOrder(

    /**
     * 仓库物品调动单
     */
    @TableId(value = "id", type = IdType.AUTO)
    var id: Long,

    /**
     * 公司id
     */
    @TableField("company_id")
    var companyId: Long= getContext().companyId,

    /**
     * 入库
     */
    @TableField("in_dept_id")
    var inDeptId: Long ,

    @TableField(exist = false)
    var inName: String? = null,

    /**
     * 创建时间
     */
    @TableField("create_time")
    var createTime: Date= Date(),

    /**
     * 订单时间
     */
    @TableField("order_time")
    var orderTime: Date? = null,

    /**
     * 出库确认时间
     */
    @TableField("out_deal_time")
    var outDealTime: Date? = null,

    /**
     * 入库确认时间
     */
    @TableField("in_deal_time")
    var inDealTime: Date? = null,

    /**
     * 入库状态
     */
    @TableField("in_status")
    var inStatus: Status = Status.UNKNOWN,

    /**
     * 出库状态
     */
    @TableField("out_status")
    var outStatus: Status = Status.UNKNOWN,

    /**
     * 数据有效性
     */
    @TableField("enabled")
    var enabled: Int=1,

    /**
     * 调度单号
     */
    @TableField("dispatch_num")
    var dispatchNum: String = generateOrder("D"),

    /**
     * 出库
     */
    @TableField("out_dept_id")
    var outDeptId: Long = getContext().subCompanyId,

    @TableField(exist = false)
    var outName: String? = null,


    @TableField("in_user_id")
    var inUserId: Long? = null,

    @TableField(exist = false)
    var inUserName : String ? = null,

    @TableField("out_user_id")
    var outUserId: Long? = null,

    @TableField(exist = false)
    var outUserName : String ? = null,

    @TableField("create_user_id")
    var createUserId: Long= getContext().userId,

    @TableField("create_dept_id")
    var createDeptId:Long = getContext().subCompanyId,

    @TableField(exist = false)
    var createUserName : String ? = null,

    @TableField(exist = false)
    var details: List<WarehouseDispatchOrderDetail>? = null,

    ):NeedGerId{

    @TableField(exist = false)
    override val idName: String = "seq_warehouse_dispatch_order"

    val orderIsSelf: Boolean
        get() {
            return createUserId == getContext().userId
        }



    companion object : GenerateNum()
}
